
/**
 * 
 * 
 * map 的封装类
 * 
 * @param map 地图组件
 * 
 * 使用方式：
 *  var mt = new mapTools(map);
 *  mt.addMarker(20,30,244,'img/marker-blue.png');
 * 
 * 
 * 
 * */
function mapTools(map){
	
	
	/***
	 * 
	 * 添加一个markers
	 * @param markersName markers的中文名称
	 * 
	 * */
	this.addMarkers=function(markersName){
		var markers = new OpenLayers.Layer.Markers(markersName);
		map.addLayer(markers);
		return markers;
	};
   
    
    /**
     * 鼠标点击Marker的响应函数
     */
    this.openPlayer=function(evt)
    {
    	
        Ext.create("wufe.util.tools.ExtPlayer",{
        	playUrl:comm.basePath+"test/sy/main.swf"
        }).show();
        OpenLayers.Event.stop(evt);
    };
    
    
    /**
     * 添加单击填出视频播放的marker
     * @param x坐标
     * @param y坐标
     * @param opacity 透明度
     * @param iconPath 要显示的icon的地址
     * 
     *  var mt = new mapTools(map);
	 *	var markers = mt.addMarkers();
	 *	mt.addPlayerMarker(markers,106.70301, -57.61578, 1,comm.basePath+"test/sy/marker.png");
     * 
     * */
    this.addPlayerMarker=function(markerLayers,x, y, opacity,iconPath){
    	var marker = this.addMarker(markerLayers,x, y, opacity,iconPath);
    	if(!marker){
    		return null;
    	}
    	marker.events.register('mousedown', marker, this.openPlayer);
    	return marker;
    }
    
    
    
    /**
     * 添加mark图标
     * @param x坐标
     * @param y坐标
     * @param opacity 透明度
     * @param iconPath 要显示的icon的地址
     * 
     * */
    this.addMarker=function(markerLayers,x, y, opacity,iconPath) 
    {
    	
    	var size = new OpenLayers.Size(50,50);
        var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
        var icon = new OpenLayers.Icon(iconPath, size, offset);
    	
    	var marker = new OpenLayers.Marker(new OpenLayers.LonLat(x, y),icon);
        //透明度
        marker.setOpacity(opacity);
        //注册鼠标事件
        //marker.events.register('mousedown', marker, this.onMakerMouseDown);

        markerLayers.addMarker(marker);
        
        return marker;

    };
	
    
    
    /**
     * 移动mark的位置
     * @param marker 要移动的marker
     * @param x坐标
     * @param y坐标
     * 
     * */
    this.markMoveTo=function(marker,x,y){
    	marker.moveTo(new OpenLayers.Pixel(x,y));
    };
    
    
    
	 
	 
	/**
	* 覆盖包围区域，如行政区域,所有参数都是必须的
	* @param map map对象
	* @param vectorName vector 的名字，可以随便写
	* @param kmlUrl kml的路径如：kml/xcq.kml
	* @param fillColor 填充色，建议传入值为： "white" 
	* @param strokeColor 边线色
	*  
	*/
	this.coverArea=function(map,vectorName,kmlUrl,fillColor,strokeColor){

		 var xcqVector = new OpenLayers.Layer.Vector(vectorName, {//加载区边界KML
			    isBaseLayer: false,
				styleMap: new OpenLayers.StyleMap({
					pointRadius: 3,
					fillColor: fillColor,
					fillOpacity:0.1,
					strokeColor: strokeColor,
					strokeWidth: 2
				}),
				strategies: [new OpenLayers.Strategy.Fixed()],
				protocol: new OpenLayers.Protocol.HTTP({
					url: kmlUrl,
					format: new OpenLayers.Format.KML({
						extractStyles: false, 
						extractAttributes: false,
						maxDepth: 2
					})
				})
		});

	    map.addLayer(xcqVector);
	};
	 
	 
	 
}